﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Model;
using MsDAL;
using System.ComponentModel;
using Components;

namespace ServiceHelper
{
    [DataObjectAttribute]
    public partial class Sys0a02Manager : Sys0a02Base
    {
        private Sys0a02DAL sys0a02Dal = new Sys0a02DAL();

        private static Sys0a02Manager _entity;

        public static Sys0a02Manager Entity
        {
            get
            {
                if (_entity == null)
                    _entity = new Sys0a02Manager();
                return _entity;
            }
        }

        #region 个人代码

        public DataTable GetListByRoleCode(string rolcode)
        {
            return sys0a02Dal.GetListByRoleCode(rolcode);
        }

        public SqlApp DeleteByRolecode(string rolecode)
        {
            return sys0a02Dal.DeleteByRolecode(rolecode);
        }

        public SqlApp AddIfNotExists(Model.Sys0a02 sys0a02)
        {
            return sys0a02Dal.AddIfNotExists(sys0a02);
        }

        public SqlApp DeleteByUsercode(string code)
        {
            return sys0a02Dal.DeleteByUsercode(code);
        }

        /// <summary>
        /// 界面回写方法
        /// </summary>
        /// <param name="summary"></param>
        /// <param name="dtl"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public string SaveData(Hashtable summary, DataTable dtl, DataTable deldata, string action,string usercode)
        {
            List<SqlApp> lst = new List<SqlApp>();

            /**
             *  点击提取明细、删除的明细会影响到数据库
             *  没有点击提取明细、相当于修改
             * */
            bool isModify = "1" == Validation.ToString(summary["hastake"]);
            string rolecode = Validation.ToString(summary["rolecode"]);
            Sys0a02 model = null;

            if (isModify) //修改的情况下，我先全部删掉
            {
                lst.Add(Sys0a02Manager.Entity.DeleteByRolecode(rolecode));
            }

            if (dtl != null)
            {
                foreach (DataRow dr in dtl.Rows)
                {
                    model = new Sys0a02();
                    model.Usercode = Validation.ToString(dr["usercode"]);
                    model.Rolecode = rolecode;

                    if (isModify)
                        lst.Add(Sys0a02Manager.Entity.Add(model));
                    else
                        lst.Add(Sys0a02Manager.Entity.AddIfNotExists(model));
                }
            }

            return CommonManager.Entity.SaveData(lst);
        }

        #endregion
    }
}



